#include "ScanBehaviour.h"
#include "Common/Tasks.h"

/*
 * Otacaj sa zatial co hladas loptu, alebo nieco ine.
 *
 * @return uhol, o ktory sa hrac otoci
 */
float ScanBehaviour::Behave()
{
	world->me->bNeckSynchronization = false;

	float uhol = 0;
	const float TURNFACTOR = 0.875f;
	
	GetTurnNeckToBehaviour()->NeckSynchronizationWithVI(ALIG_NECK);

	switch(world->me->GetViewWidth())
	{
	case NARROW_VIEW:
		
	GetTurnNeckToBehaviour()->NeckSynchronizationWithVI(NOR_VIEW);
	// tu nie je break naschval

	case NORMAL_VIEW:
		uhol = world->params->server->visible_angle * TURNFACTOR;
		break;

	case WIDE_VIEW:
		uhol = world->params->server->visible_angle * TURNFACTOR * 2.0f;
		break;
	}

	commandGenerator->Turn(GetRunToPositionBehaviour()->CompMoment(uhol));

	//synchronizacia
	DATA_STORAGE.SetNextSynchMode(Synch_WaitForVI);

	return uhol;
}

/*
 * Hrac preskuma najblizsie okolie okolo seba otocenim sa okolo vlastnej osi
 */
void ScanBehaviour::ExamineSurroundings()
{
	// Skenovanie okolia - kontrola situacie pred zahranim.
	world->me->bNeckSynchronization = false;
	
	if(DATA_STORAGE.scanBeforeKickOffAngle <= 360)
	{
		DBGN("Skenujem okolie");
		
		DATA_STORAGE.scanBeforeKickOffAngle += Behave();
		return;
	}
}
